M4=m4
PERL=perl
PDFLATEX=pdflatex
BIBTEX=bibtex

PARTS=pre.bib.m4 2000.bib.m4 2001.bib.m4 2002.bib.m4 2003.bib.m4 2004.bib.m4 \
    2005.bib.m4 2006.bib.m4 2007.bib.m4 2008.bib.m4 2009.bib.m4

.DEFAULT: all
.PHONY: all clean

all: aosd-bib.bib report.pdf

aosd-bib.bib: aosd-bib.m4 macros.m4 config.m4 $(PARTS)
	$(M4) -P $< | $(PERL) utf8conv.pl > $@

report.aux: | report.tex
	$(PDFLATEX) report

report.bbl: report.aux aosd-bib.bib
	$(BIBTEX) report

report.pdf: report.tex report.aux report.bbl aosd-bib.bib
	@cp -p report.aux report.aux.bak
	$(PDFLATEX) report
	@if cmp -s report.aux report.aux.bak; then touch -r report.aux.bak report.aux; \
	else NEWS="$$NEWS -W report.aux"; fi; rm report.aux.bak; \
	if [ -n "$$NEWS" ]; then $(MAKE) $$NEWS $@; fi

clean:
	rm -f aosd-bib.bib
	rm -f report.aux report.log report.blg report.bbl report.pdf
